package cn.ex.ymcc.web.controller;

import cn.ex.ymcc.dto.PayApplyDto;
import cn.ex.ymcc.service.IPayOrderService;
import cn.ex.ymcc.domain.PayOrder;
import cn.ex.ymcc.query.PayOrderQuery;
import cn.ex.ymcc.result.JSONResult;
import cn.ex.ymcc.result.PageList;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/payOrder")
public class PayOrderController {

    @Autowired
    public IPayOrderService payOrderService;

    /**
     * 根据订单号校验支付单是否已经存在
     * @param orderNo
     * @return
     */
    @GetMapping("/checkPayOrder/{orderNo}")
    public JSONResult checkPayOrder(@PathVariable("orderNo") String orderNo){
        PayOrder payOrder = payOrderService.selectByOrderNo(orderNo);
        // 支付单已经存在那么就返回success  支付单没有存在就返回false
        return payOrder == null? JSONResult.error() : JSONResult.success();
    }

    /**
     * 发起支付申请
     * @param dto
     * @return
     */
    @PostMapping("/apply")
    public JSONResult apply(@RequestBody PayApplyDto dto){
        String formStr= payOrderService.apply(dto);// 向支付宝发起申请  返回from表单
        return JSONResult.success(formStr);
    }



}
